﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Diagnostics.Contracts;

namespace DataStructure.Interview
{
    public class Question5
    {
        public static string EncodeSpace(string s)
        {
            int spacecount = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == ' ') spacecount++;
            }

            char[] data = new char[ s.Length + 2 * spacecount];
            int index = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == ' ')
                {
                    data[index++]= '%';
                    data[index++] = '2';
                    data[index++] = '0';
                }
                else
                {
                    data[index++] = s[i];
                }
            }

            return new string(data);
        }

    }
}
